const http=require("http");
const path=require("path");
const fs=require("fs");

http.createServer((req,res)=>{

    fs.readFile('青苹果jpg.jpg',(error,data)=>{
        if(error){
            res.writeHead(500,{'content-type':'text/plain'})
            res.end("读取图片失败");
            return;
        }
        const base64Img=data.toString('base64');
        const imgDataUrl=`data:image/jpeg;base64,${base64Img}`
    })
    const html=
    `<!DOCTYPE html>
      <html lang="zh-CN">
      <head>
        <meta charset="UTF-8">
        <title>图片展示</title>
      </head>
      <body>
        <h1>这是一张通过 data URI 展示的图片</h1>
        <img src="${imgDataUrl}" alt="青苹果jpg">
      </body>
      </html>`;
      res.writeHead(200,{'content-type':'text/html'});
      res.end(html);
}).listen(8081);
console.log("server is listening http://localhost:8081");